
/*  
    startWin.cpp
    Реализация ввода размера картинки -> startWin.h
*/

#include "include/startWin.h"
#include "include/types.h"

#include <iostream>
#include <curses.h>
#include <ncurses.h>
#include <string>

using namespace std;

#define WINBOXW 25
#define WINBOXH 5

const string textWidth = "Width: ";
const string textHeight = "Height: ";
const string textError = "Error num < 0!!!";

class WinBox {
    public:
        int x;
        int y;
};

int createWinMenu(WinBox &winBox, int num, int y, int x);

void startMenu(vector<uint32> &size, int yWin, int xWin) {
    
    WinBox winBox;
    winBox.x = WINBOXW;
    winBox.y = WINBOXH;

    size[0] = (uint32)createWinMenu(winBox, 0, yWin, xWin);
    size[1] = (uint32)createWinMenu(winBox, 1, yWin, xWin);

}


int createWinMenu(WinBox &winBox, int num, int y, int x) {
    int size = 0;

    WINDOW *input = newwin(winBox.y, winBox.x, (y / 2) - (winBox.y / 2), (x / 2) - (winBox.x / 2));
    box(input, 0, 0);
    refresh();
    wrefresh(input);
    keypad(input, true);

    do {
        if (num == 0) {
            mvwprintw(input, winBox.y/2, (winBox.x/2)-textWidth.size(), "%s", textWidth.c_str());
            
        } else {
            mvwprintw(input, winBox.y/2, (winBox.x/2)-textHeight.size(), "%s", textHeight.c_str());
        }
        
        wscanw(input, "%d", &size);

        if (size <= 0) {
            mvwprintw(input, (winBox.y/2)-1, (winBox.x/2)-textError.size(), "%s", textError.c_str());
        } else {
            break;
        }

    } while(1);

    delwin(input);
    return size;
}